<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
       
        #app{
            width: 300px;
            height: 1000px;
            margin: 50px auto;
        }
        #app>.top{
            width: 100%;
            height: 20px;
            text-align:center
        }
        h2{
            margin-top: 10px;
        }
        h2>button{
            float: right;
        }
        ul>li{
            background: pink;
            margin: 2px;
        }
        ul>li>button{
            float: right;
        }
    </style>
</head>
<body>
    <div id="app">
        <div class="top">
            <input v-model = "val" type="text">
            <button @click = "addItem">添加</button>
        </div>
        
        <div>
            <h2>
                正在进行  ---  {{ len }}
                <!-- <button @click="deleteAll">删除全部</button> -->
            </h2>
            <ul>
                <li v-for="(item, index) in arr" v-show = "!item.checked">
                    <input v-model = "item.checked" type="checkbox">
                    {{ item.val }}     
                    <button @click="deleteSelected">删除</button>
                </li>
            </ul>

            <h2>
                已经完成  ---  {{ arr.length - len }}
                <!-- <button @click="deleteAll">删除全部</button> -->
            </h2>
            <ul>
                <li v-for="(item, index) in arr" v-show = "item.checked">
                    <input v-model = "item.checked" type="checkbox">
                    {{ item.val }}     
                    <button @click="deleteSelected">删除</button>
                </li>
            </ul>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        new Vue({
            el: "#app",
            data: {
                // input中输入的值
                val: "",
                // 总的任务
                arr: []
            },
            // created() {
                // forEach  没有返回值
                // map   有返回值
                // filter   做筛选
                // var datas = this.arr.filter((item) => {
                //     return item === 2
                // })
                // // [2]
                // console.log(datas)
            // }, 
            computed: {
                len() {
                    return this.arr.filter((item) => {
                        return item.checked === false
                    }).length
                }
            },
            methods: {
                addItem() {
                    this.arr.push({
                        val: this.val,
                        checked: false
                    })
                    this.val = ""
                },
                deleteSelected(){
                    this.arr.splice(0,1)
                },
               
                // deleteAll(){
                //     this.arr.splice(0)
                // }, 
                
                // deleteAll(){
                //     this.arr.splice(0)
                // },
            }
        })
    </script>
</body>
</html>